$(function () {
  let params = {};

  location.search
    .slice(1)
    .split("&")
    .forEach((item, i) => {
      params[item.split("=")[0]] = item.split("=")[1];
    });
  //获取地址栏参数————————————————————————————————————————————————————————

  //商品信息接口
  $.ajax({
    url: "http://chst.vip:1234/api/getproduct",
    data: {
      productid: params.productid,
    },
    success: (res) => {
      let proType = /.{1,}\(.+\)/.exec(res.result[0].productName);

      let htm = `
    <!-- 导航 -->
    <nav class="nav">
      <a href="../index.html">首页></a>
      <a href="category.html">全部分类></a>
      <a href="404.html">${proType[0]}</a>
      <a href="" class="navright">筛选</a>
    </nav>
    <!-- 产品详情 -->
    <dl>
        <dt>
            ${res.result[0].productImg}
        </dt>
        <dd>
        <b>${res.result[0].productName}</b>
        </dd>
    </dl>
    ${res.result[0].bjShop}
    <div class='com'>
        <ul></ul>
    </div>
    `;

      //评论信息接口
      $("div#product").html(htm);
      $.ajax({
        url: "http://chst.vip:1234/api/getproductcom",
        data: {
          productid: params.productid,
        },
        success: (res2) => {
          let htm2 = "";
          $.each(res2.result, (i, item) => {
            htm2 += `
            <li class="comDetail">
                  <h5>
                      <span>${item.comName}o</span>
                      <span>${item.comTime}</span>
                  </h5>
                  <p class="comContent">${item.comContent}</p>
                  <h6 class="comFrom">${item.comFrom}</h6>
            </li>
              `;
          });
          $("div.com ul").html(htm2);
        },
      });
    },
  });

  $(".more a").text("更多评论>>");
});
